/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package window;

import data.Data;
import java.util.Observable;
import java.util.Observer;
import windowComponents.EmailFolderPanel;

/**
 *
 * @author Arcanis
 */
public class EmailsPanel extends javax.swing.JPanel implements Observer{

    /**
     * Creates new form EmailPanel
     */
    public EmailsPanel() {
        initComponents();                           
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 542, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof Data){
            Data d = (Data)o;
            jTabbedPane1.removeAll();
            for(String item : d.getFolderNames()){                
                EmailFolderPanel panel = new EmailFolderPanel(d.getContacts());
                d.getFolder(item).addObserver(panel);
                panel.update(d.getFolder(item), "");
                panel.setSize(this.getSize());
                jTabbedPane1.add(item, panel);
            }
        }
    }
}
